
#include<iostream>
#include<vector>
#include<string>
using namespace std;


//
//vector<int> searchRange(vector<int>& nums, int target) {
//    int left = 0, right = nums.size() - 1, mid = 0;
//    vector<int> ret;
//    while (left < right)
//    {
//        mid = (left + (right - left)) / 2;
//        if (nums[left] < target) left = mid + 1;
//        else right = mid;
//        if (left == right) break;
//    }
//    if (nums[left] != target) return { -1,-1 };
//    ret.push_back(left);
//    left = 0, right = nums.size()-1;
//    while (left < right)
//    {
//        mid = (left + (right - left + 1)) / 2;
//        if (nums[left] <= target) left = mid;
//        else right = mid - 1;
//        if (left == right) break;
//    }
//    ret.push_back(right);
//    if (nums[right] != target) return { -1,-1 };
//    return ret;
//
//}


vector<int> searchRange(vector<int>& nums, int target) {
    if (nums.size() == 0) return { -1,-1 };
    int left = 0, right = nums.size() - 1, mid = 0;
    while (left < right) {
        mid = left + (right - left) / 2;
        if (nums[mid] < target) left = mid + 1;
        else right = mid;
    }
    if (nums[left] != target)return { -1, -1 };
    int begin = left;
    left = 0, right = nums.size() - 1;
    while (left < right) {
        mid = left + (right - left + 1) / 2;
        if (nums[mid] <= target) left = mid;
        else right = mid - 1;
    }
    return { begin,right };
}
int main()
{
    vector<int> v = { 5,7,7,8,8,10 };
    searchRange(v, 8);

    return 0;
}